#!/usr/bin/env python
# -*- coding:utf-8 -*-
from django.shortcuts import render,HttpResponse
from app01.forms import account as AccountForm

def login(request):
    obj = AccountForm.LoginForm(request.POST)
    if request.method=='POST':
        if obj.is_valid():
            all_data = obj.clean()
        else:
            #为什么使用sample_tag去取值，而不取好了再传到html，因为如果字段很多的话，要分别定义每个的错误；
            error = obj.errors.as_json()
            return HttpResponse(error)
            # return render(request,'account/login.html',{'obj':obj,'error':error})
    return render(request,'account/login.html',{'obj':obj})


# {
#     "username": [
#         {"message": "This field is required.", "code": "required"}
#     ],
#     "password": [
#         {"message": "This field is required.", "code": "required"}
#     ]
# }